<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/common/taglibs.jsp"%>
<%@include file="/common/javascript.jsp"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>角色</title>
    <script type="text/javascript">
    $(function () {
       $("#maingrid4").ligerGrid({
            columns: [
      				{ display: '代码', name: 'roleId', align: 'left', width:'15%', minWidth: 60 },
    				{ display: '名称', name: 'roleName', width:'25%',minWidth: 120 },
    				{ display: '描述', name: 'roleDescription',width:'40%', minWidth: 140 }
            ],  pageSize:10,
            dataAction: 'server', url: '${ctx}/role/list?search_EQ_isEnable=T', sortName: 'roleId',
            width: '100%', height: '80%', numPerPage:20,rownumbers:true,
            isChecked: f_isChecked, onCheckRow: f_onCheckRow, onCheckAllRow: f_onCheckAllRow,
            checkbox:true
        }); 
        $("#pageloading").hide();
    });
    


    var checkedRoles = [];
    
    function f_onCheckAllRow(checked)
    {
        for (var rowid in this.records)
        {
            if(checked)
                addChecked(this.records[rowid]);
            else
                removeChecked(this.records[rowid]);
        }
    }
    
    function addChecked(row)
    {
        if(findCheckedRole(row) == -1)
            checkedRoles.push(row);
    }
    
    function removeChecked(row)
    {
        var i = findCheckedRole(row);
        if(i==-1) return;
        checkedRoles.splice(i,1);
    }
    
    function findCheckedRole(row)
    {
        for(var i =0;i<checkedRoles.length;i++)
        {
            if(checkedRoles[i].roleId == row.roleId){
            	return i;
            }
        }
        //父窗口已选择的
        var options=window.parent.getSelectRoles();
        for(var i=0;i<options.length;i++)
        {
        	if($(options[i]).val()==row.roleId){
        		return i;
        	}
        }
        return -1;
    }

    function f_isChecked(rowdata)
    {
        if (findCheckedRole(rowdata) == -1){
        	 return false;
        }
        return true;
    }
    
    function f_onCheckRow(checked, data)
    {
        if (checked){
        	addChecked(data);
        }else{
        	removeChecked(data);
        }
    }
   
    
    function selectOK(){
    	window.parent.callBackOK(checkedRoles);
    }
    
    function selectCancel(){
    	window.parent.callBackCancel();
    }
    </script>
</head>
<body style="padding:6px; overflow:hidden;">
  <div class="l-clear"></div>
    <div id="maingrid4" style="margin-top:0px;"></div>
	<div class="l-dialog-buttons" style="">
		<div class="l-dialog-buttons-inner">
			<div class="l-dialog-btn">
				<div class="l-dialog-btn-l"></div>
				<div class="l-dialog-btn-r"></div>
				<div class="l-dialog-btn-inner" onclick="selectCancel()">取消</div>
			</div>
			<div class="l-dialog-btn">
				<div class="l-dialog-btn-l"></div>
				<div class="l-dialog-btn-r"></div>
				<div class="l-dialog-btn-inner" onclick="selectOK()">提交</div>
			</div>
			<div class="l-clear"></div>
		</div>
	</div>
  <div style="display:none;">
</body>
</html>
